﻿// IPC Library
// Interprocess Communication Library
// Copyright(C)2008 Bill Tudor
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Globalization;

namespace IPCLibrary
{
	/// <summary>
	/// IPC Library Exception.
	/// </summary>
	/// <remarks>
	/// This exception type is used for all library-generated exceptions.
	/// </remarks>
	[Serializable]
	public class IPCException : System.Exception
	{
		/// <summary>
		/// Default constructor.
		/// </summary>
		public IPCException()
			: base() { }
		/// <summary>
		/// Create a new IPC exception.
		/// </summary>
		/// <param name="message">Exception message.</param>
		public IPCException(string message)
			: base(message) { }
		/// <summary>
		/// Create a new IPC exception.
		/// </summary>
		/// <param name="message">Exception message.</param>
		/// <param name="innerException">Inner exception.</param>
		public IPCException(string message, Exception innerException)
			: base(message, innerException) { }
		/// <summary>
		/// Create a new IPC exception.
		/// </summary>
		/// <param name="info">Serialization information.</param>
		/// <param name="context">Serialization context.</param>
		protected IPCException(SerializationInfo info, StreamingContext context)
			: base(info, context) { }
		internal static IPCException FromLastError(string message, string functionName)
		{
			int err = NativeMethods.GetLastError();
			return new IPCException(String.Format(CultureInfo.CurrentCulture, "{0} [Win32Method={1}; GetLastError()={2}", message, functionName, err));
		}
	}
}
